package com.fruit.web.vo.customer;

import java.io.Serializable;


import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import com.fruit.controller.LoginController;
import com.fruit.service.ICouponService;
import com.fruit.utils.DESPlusUtil;
import com.fruit.utils.DateTimeUtil;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.PageExistUtil;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.Consultation;
import com.fruit.web.bo.impl.Coupon;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.ManageBeanConstants;
import com.fruit.web.constant.SpringBeanConstants;
import com.fruit.web.vo.common.ConsultationPage;
import com.fruit.web.vo.common.CouponPage;

@ManagedBean(name="customerConsultationPage")
@SessionScoped
public class CustomerConsultationPageBean implements Serializable {
	private static final long serialVersionUID = -8106629465344224756L;
	
	private ConsultationPage oPage;
	
	private ConsultationPage nPage;
	
	private ConsultationPage rPage;
	

	public ConsultationPage getoPage() {
		return oPage;
	}

	public void setoPage(ConsultationPage oPage) {
		this.oPage = oPage;
	}

	public ConsultationPage getnPage() {
		return nPage;
	}

	public void setnPage(ConsultationPage nPage) {
		this.nPage = nPage;
	}

	public ConsultationPage getrPage() {
		return rPage;
	}

	public void setrPage(ConsultationPage rPage) {
		this.rPage = rPage;
	}

	public CustomerConsultationPageBean(){
		LoginCustomerPageBean loginCustomerPage = (LoginCustomerPageBean)SpringFacesUtil.getManagedBean(ManageBeanConstants.LOGIN_CUSTOMER_PAGE_BEAN_NAME);
		Consultation paraO = new Consultation();
		paraO.setStatusCode(EjdConstants.CONSULTATION_STATUS_O);
		paraO.setCustomer(loginCustomerPage.getCustomerInfo());
		oPage = new ConsultationPage(1,10,paraO);
		oPage.getPageDatasForCustomer();
		Consultation paraN = new Consultation();
		paraN.setStatusCode(EjdConstants.CONSULTATION_STATUS_N);
		paraN.setCustomer(loginCustomerPage.getCustomerInfo());
		nPage = new ConsultationPage(1,10,paraN);
		nPage.getPageDatasForCustomer();
		Consultation paraR = new Consultation();
		paraR.setStatusCode(EjdConstants.CONSULTATION_STATUS_R);
		paraR.setCustomer(loginCustomerPage.getCustomerInfo());
		rPage = new ConsultationPage(1,10,paraR);
		rPage.getPageDatasForCustomer();
	}
	
	public String selectoPageNo() {
		String result = null;
		String pageNo = (String) SpringFacesUtil.getRequestParameter("pageNo");
		if (this.getoPage().getPageNo().intValue() == Integer.valueOf(pageNo).intValue()) {
			return result;
		}
		this.getoPage().setPageNo(Integer.valueOf(pageNo).intValue());
		this.getoPage().getPageDatasForCustomer();
		return result;	
	}
	public String selectnPageNo() {
		String result = null;
		String pageNo = (String) SpringFacesUtil.getRequestParameter("pageNo");
		if (this.getnPage().getPageNo().intValue() == Integer.valueOf(pageNo).intValue()) {
			return result;
		}
		this.getnPage().setPageNo(Integer.valueOf(pageNo).intValue());
		this.getnPage().getPageDatasForCustomer();
		return result;	
	}
	public String selectrPageNo() {
		String result = null;
		String pageNo = (String) SpringFacesUtil.getRequestParameter("pageNo");
		if (this.getrPage().getPageNo().intValue() == Integer.valueOf(pageNo).intValue()) {
			return result;
		}
		this.getrPage().setPageNo(Integer.valueOf(pageNo).intValue());
		this.getrPage().getPageDatasForCustomer();
		return result;	
	}
	public String goDetailPage(){
		String result = "";
		String primaryCategoryCode = (String) SpringFacesUtil.getRequestParameter("primaryCategoryCode");
		String code =(String) SpringFacesUtil.getRequestParameter("code");
		String productId =(String) SpringFacesUtil.getRequestParameter("productId");
		String specialField1 = (String) SpringFacesUtil.getRequestParameter("specialField1");
		String specialField2 = (String) SpringFacesUtil.getRequestParameter("specialField2");
		if (PageExistUtil.checkPageExist(code+".xhtml", "/layout/goods/" + primaryCategoryCode) && PageExistUtil.checkPageExist(code+"Detail.xhtml", "/layout/goods/" + primaryCategoryCode + "/sub") ) {
			result =  "/layout/goods/" + primaryCategoryCode + "/" + code + "?faces-redirect=true&primaryCategoryCode=" + DESPlusUtil.encrypt(primaryCategoryCode) + "&code=" + DESPlusUtil.encrypt(code) + "&productId=" + DESPlusUtil.encrypt(productId);
			if (null != specialField1 && !("".equals(specialField1))) {
				result = result + "&specialField1=" + DESPlusUtil.encrypt(specialField1);
			}
			if (null != specialField2 && !("".equals(specialField2))) {
				result = result + "&specialField2=" + DESPlusUtil.encrypt(specialField2);
			}
			return result;
		} else {
			return "/WEB-INF/" + EjdConstants.NO_PRODUCT_DETAIL_PAGE;
		}
	}
	
}
